package com.xunyin.modules.quartz.task;

import com.xunyin.modules.mtstore.domain.MtStoreRoom;
import com.xunyin.modules.mtstore.service.MtStoreRoomService;
import com.xunyin.modules.mtstore.service.mapper.MtStoreRoomMapper;
import com.xunyin.modules.shareorder.service.TShareOrderService;
import com.xunyin.modules.shareorder.vo.TShareOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class ShareOrderTask {

    private final TShareOrderService tShareOrderService;

    //private final TStoreRoomService tStoreRoomService;
    private final MtStoreRoomService mtStoreRoomService;

    private final MtStoreRoomMapper mtStoreRoomMapper;


    public ShareOrderTask(TShareOrderService tShareOrderService
            ,MtStoreRoomService mtStoreRoomService
            , MtStoreRoomMapper mtStoreRoomMapper) {

        this.tShareOrderService = tShareOrderService;
        this.mtStoreRoomService = mtStoreRoomService;
        this.mtStoreRoomMapper = mtStoreRoomMapper;
    }

    public void run() {

        List<MtStoreRoom> storeRoomList = mtStoreRoomService.list();
        for(MtStoreRoom mtStoreRoom : storeRoomList){

            List<TShareOrderVo> list = tShareOrderService.orderListByRoomId(mtStoreRoom.getId());

            //log.info("ShareOrderTask-tStoreRoom.getId():"+tStoreRoom.getId());
            //log.info("ShareOrderTask-list:"+list);
            //log.info("ShareOrderTask-list.size():"+list.size());
            // 如果包间没有服务中的订单，则设置包间为空闲中
            if(list.size()<=0){

                if(mtStoreRoom.getStoreRoomStatus() == 1){

                    mtStoreRoomMapper.updateStoreRoomStatus1(0,mtStoreRoom.getId());

                }
            }
        }
    }
}
